package com.example.demo05.service.impl;

import com.example.demo05.pojo.Clock;
import com.example.demo05.mapper.ClockMapper;
import com.example.demo05.pojo.ClockTable;
import com.example.demo05.pojo.User;
import com.example.demo05.service.ClockService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author anxuan
 * @since 2021-06-19
 */
@Service
public class ClockServiceImpl extends ServiceImpl<ClockMapper, Clock> implements ClockService {
    @Autowired
    ClockMapper clockMapper;

    @Override
    public void upFlag(){
        clockMapper.upFlag();
    }


    @Override
    public List<ClockTable> selectAll() {
        return clockMapper.selectAll();

    }

    @Override
    public List<ClockTable> selectTem(){ return clockMapper.selectTem(); }

    @Override
    public void newClock(Clock clock){

        clockMapper.newClock(clock);
        clockMapper.upState();
        clockMapper.setFlag(clock);
    }

    @Override
    public List<ClockTable> timeRise(){
        List<ClockTable> list=clockMapper.selectAll();
        Collections.sort(list, new Comparator<ClockTable>() {
            @Override
            public int compare(ClockTable o1, ClockTable o2) {
                return o1.getClockTime().compareTo(o2.getClockTime());
            }
        });
        return list;
    }

    @Override
    public List<ClockTable> timeDrop(){
        List<ClockTable> list=clockMapper.selectAll();
        Collections.sort(list, new Comparator<ClockTable>() {
            @Override
            public int compare(ClockTable o1, ClockTable o2) {
                return o2.getClockTime().compareTo(o1.getClockTime());
            }
        });
        return list;
    }

    @Override
    public void upState(){
        clockMapper.upState();
    }

    @Override
    public List<ClockTable> selectTime(String time){
        List<ClockTable> list1 = clockMapper.selectAll();
        List<ClockTable> list2=null;
        for(int i=1;i<list1.size();i++){

        }
        return list2;

    }


}
